package com.tramp.frame.server.pageplugin;

import com.tramp.frame.server.interceptor.SqlInterceptor;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * @author chenjm1
 * @since 2017/10/20
 */
@Configuration
public class MybatisPageConf {

    @Bean
    public SqlInterceptor sqlInterceptor() {
        SqlInterceptor sqlInterceptor = new SqlInterceptor();
        return sqlInterceptor;
    }

    @Bean
    public PageInfoHolder pageInfoHolder() {
        PageInfoHolder sqlInterceptor = new PageInfoHolder();
        return sqlInterceptor;
    }

    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {

        return new EmbeddedServletContainerCustomizer() {
            @Override
            public void customize(ConfigurableEmbeddedServletContainer container) {
                ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
                container.addErrorPages(error404Page);
            }
        };
    }

}
